/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template sigFile, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.di.server;

import cn.ac.iie.di.cnt.JsonCntSender;
import cn.ac.iie.di.ftp.FtpDownloadFile;
import cn.ac.iie.di.global.GlobalParas;
import cn.ac.iie.di.gwxs.JsonGwxSender;
import cn.ac.iie.di.splitor.FileListener;
import cn.ac.iie.di.splitor.FileRead;
import cn.ac.iie.di.splitor.JsonSplitor;
import cn.ac.iie.di.splitor.UntarSplitor;
import cn.ac.iie.di.untar.TarHandler;
import iie.mm.client.ClientAPI;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

/**
 *
 * @author lenovo-pc
 */
public class GwxParserStartup {

    static Logger logger = null;
    public static Logger errorLogger = null;

    static {
        PropertyConfigurator.configure(ClassLoader.getSystemClassLoader().getResource("log4j.properties"));
        logger = Logger.getLogger(GwxParserStartup.class.getName());
        errorLogger=Logger.getLogger("errorlog");
    }

    public static void main(String[] args) {
        try {
            //ftp下载
//            for (int i = 0; i < 1; i++) {
//                FtpDownloadFile fdf = new FtpDownloadFile();
//                Thread th = new Thread(fdf);
//                th.setName("FtpDownloadFile - " + i);
//                th.start();
//            }
            //轮询tar包 解压tar包
//            startunTarFile();
//            startTarSplitor();
            //轮询文件 处理文件
            startGwxSender();
            startJsonSplitor();
            Thread monter = new Thread(new Monter());
            monter.setName("MonterThead");
            monter.start();

        } catch (Exception ex) {
            logger.error(ex, ex);
        }
    }

    public static void startGwxSender() throws InterruptedException {
        for (int i = 0; i < GlobalParas.HashCode; i++) {
            Thread thread = new Thread(new JsonGwxSender());
            thread.setName("JsonGwxSender" + "_" + i);
            thread.start();
            Thread.sleep(3000);
        }
        for (int i = 0; i < 4; i++) {
            Thread thread1 = new Thread(new JsonCntSender());
            thread1.setName("JsonCntSender" + "_" + i);
            thread1.start();
            Thread.sleep(3000);
        }
    }

    public static void startunTarFile() {
        for (int i = 0; i < 4; i++) {
            Thread thread = new Thread(new TarHandler());
            thread.setName("TarHandler" + "_" + i);
            thread.start();
        }
    }

    public static void startTarSplitor() {
        Thread thread = new Thread(new UntarSplitor(GlobalParas.ORI_GWX, GlobalParas.FILE_NEWS));
        thread.setName("UntarSplitor" + "_gwx");
        thread.start();
    }

    public static void startJsonSplitor() {
//        Thread thread = new Thread(new JsonSplitor(GlobalParas.TMP_GWX, GlobalParas.DES_GWX, GlobalParas.FILE_NEWS, GlobalParas.gwxQueue));
//        thread.setName("JsonSplitor" + "_gwx");
//        thread.start();

        Thread thread = new Thread(new FileListener(GlobalParas.TMP_GWX, GlobalParas.fileQueue));
        thread.setName("FileListener" + "_gwx");
        thread.start();
        for (int i = 0; i < GlobalParas.EndCode; i++) {
            Thread thread1 = new Thread(new FileRead(GlobalParas.DES_GWX, GlobalParas.fileQueue, GlobalParas.gwxQueue));
            thread1.setName("FileRead" + "_" + i);
            thread1.start();
        }

    }

}
